using System;
using System.Collections.Generic;
using PharmacyPharnet.Core.CustomEventArgs;

namespace PharmacyPharnet.Core.ContextMenu
{
    public class CustomButtonBarItem : DevExpress.XtraBars.BarButtonItem
    {
        #region Declare
        public event BeforeExecuteHandler BeforeExecute;
        public event ExecuteHandler Execute;
        public event AfterExecuteHandler AfterExecute;
        private Pharmacy.Ultilities.Enums.PopUpItems popUpItems;
        #endregion

        #region Constructor
        
        public CustomButtonBarItem()
            : base()
        {
            this.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(CustomButtonBarItem_ItemClick);
        }

        public CustomButtonBarItem(string ItemName)
            :this()
        {
            this.Caption = ItemName;
        }

        #endregion

        #region Properties
        public Pharmacy.Ultilities.Enums.PopUpItems WhoAmI
        {
            get { return popUpItems; }
            set { popUpItems = value; }
        }
        #endregion

        #region EventHandler

        public void CustomButtonBarItem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            CustomBaseEventArg arg = new CustomBaseEventArg();
            OnBeforeExecute(arg);
            OnExecute(arg);
            OnAfterExecute(arg);
        }

        public virtual void OnBeforeExecute(CustomBaseEventArg e)
        {
            if (BeforeExecute != null)
            {
                BeforeExecute(this, e);
            }
        }

        public virtual void OnExecute(CustomBaseEventArg e)
        {
            if (Execute != null)
            {
                Execute(this, e);
            }
        }

        public virtual void OnAfterExecute(CustomBaseEventArg e)
        {
            if (AfterExecute != null)
            {
                AfterExecute(this, e);
            }
        }

        #endregion
    }
}
